import Router from 'koa-router';
import { routes } from '../../routes';
import { validationMiddleware } from '../../middleware/validationMiddleware';
import { ProductCategoryDto } from './ProductCategory.dto';
import { addProductCategory, getProductCategoryList } from '../../service/ProductCategoryService';

const router = new Router({
  prefix: '/api'
});

router.post(routes.ADMIN_PRODUCT_CATEGORY_ADD, validationMiddleware(ProductCategoryDto), async ctx => {
  return ctx.body = await addProductCategory(ctx);
});

router.get(routes.ADMIN_PRODUCT_CATEGORY_LIST, async ctx => {
  const token = ctx.headers['authorization'];
  const query = ctx.query;
  return ctx.body = await getProductCategoryList(token,query);
})


export default router.routes();